<template>
	<view class="wanl-withdraw">
		<view class="edgeInsetTop"></view>
		<view class="padding-tb-bj">
			<view class="bank">
				<view class="content" style="height: 80rpx; line-height: 80rpx">
					<text>Id</text>
				</view>
				<view class="action">
					<input type="text" :disabled="config.is_bind == 1" v-model="config.jh_id" placeholder="请输入金猴Id" />
				</view>
			</view>
			`
			<view class="bank">
				<view class="content" style="height: 80rpx; line-height: 80rpx">
					<text>金猴账号</text>
				</view>
				<view class="action">
					<input type="text" :disabled="config.is_bind == 1" v-model="config.jh_mobile" placeholder="请输入金猴账号" />
				</view>
			</view>
			<view class="bank">
				<view class="content" style="height: 80rpx; line-height: 80rpx">
					<text>转入至</text>
				</view>
				<picker
					range-key="name"
					:range="xqList"
					:value="xq"
					@change="
						(e) => {
							xq = e.detail.value;
						}
					"
				>
					<view>{{ xqList[xq]['name'] }}</view>
				</picker>
			</view>
		</view>

		<view class="padding-bj bg-white money">
			<view class="text-lg">
				<text>转入数量</text>
				<text class="text-sm wanl-gray" v-if="config.jh_sxf_rate > 0">（费率 {{ config.jh_sxf_rate }}%）</text>
			</view>
			<view class="margin-tb-bj price">
				<view class="symbol">
					<text>￥</text>
				</view>
				<input :value="money" type="digit" maxlength="5" focus @input="replaceInput" />
			</view>
			<view class="solid-top padding-top-bj">
				<block v-if="+config.jh_sxf_rate > 0">
					<text class="wanl-gray-light">服务费</text>
					<text class="text-price text-orange margin-left-xs">{{ servicemoney }}</text>
					<text class="wanl-gray-light">，</text>
				</block>
				<text class="wanl-gray-light">可用共生值</text>
				<text class="wanl-gray-light margin-lr-xs text-price">{{ +config.score }}</text>
				<text class="text-orange" v-if="+config.score > 0" @tap="moneyAll">全部</text>
			</view>
		</view>
		<view class="padding-bj margin-top">
			<!-- 1.0.5升级 -->
			<button class="mix-btn wanl-bg-redorange an" :loading="loading" :disabled="loading" @tap="withdraw">提现</button>
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
export default {
	data() {
		return {
			xqList: [
				{
					id: 0,
					name: '待行权'
				}
				// {
				// 	id: 1,
				// 	name: '可行权'
				// }
			],
			config: {
				jh_mobile: '',
				jh_id: '',
				jh_sxf_rate: ''
			},
			zh: '',
			xq: 0,
			bankData: null,
			usermoney: 0,
			money: null,
			servicemoney: 0,
			servicefee: 0,
			loading: false
		};
	},
	onLoad(e) {
		this.loadData();
	},
	computed: {
		...mapState(['user', 'common'])
	},
	methods: {
		async loadData() {
			uni.request({
				url: `/wanlshop/activity/Index/getjhconfig`,
				method: 'GET',
				success: (res) => {
					this.config = res.data;
					// this.zh = res.data.jh_mobile;
					// this.servicefee = res.data.jh_sxf_rate;
					//更新全局金额
					// this.setMoney(res.data.money);
					// //获取提现账户
					// this.bankData = res.data.bank;
					// // 服务费
					// this.servicefee = res.data.servicefee;
				}
			});
		},
		async withdraw() {
			// 1.0.5升级 修复针对多次点击
			if (this.loading) return;
			this.loading = true;
			let money = parseFloat(this.money);
			// 1.0.6升级
			if (!this.config.jh_id) {
				this.$wanlshop.msg('请填写金猴Id');
				this.loading = false;
				return;
			}
			if (!this.config.jh_mobile) {
				this.$wanlshop.msg('请填写金猴账号');
				this.loading = false;
				return;
			}
			if (money <= 0) {
				this.$wanlshop.msg('请填写正确金额');
				this.loading = false;
				return;
			}

			await uni.request({
				url: '/wanlshop/activity/Index/transfer',
				method: 'POST',
				data: {
					jh_id: this.config.jh_id,
					mobile: this.config.jh_mobile,
					num: money,
					active: this.xq
				},
				success: (res) => {
					// this.setMoney(res.data);
					// // 1.0.5升级
					// this.loading = false;
					// // 跳转成功
					uni.showToast({
						icon: 'none',
						title: '提现成功'
					});
					this.loadData();
				},
				complete: () => {
					this.loading = false;
				}
			});
		},
		setMoney(money) {
			this.usermoney = money;
			// this.$store.commit('user/setUserInfo', { score: money });
		},
		replaceInput(e) {
			this.money = e.target.value;
			this.servicemoney = e.target.value > 0 ? ((e.target.value * +this.config.jh_sxf_rate) / 100).toFixed(2) : 0;
		},
		emptyInput() {
			this.money = null;
		},
		moneyAll() {
			this.money = +this.user.score;
		},
		getCode(str) {
			str = str.replace(/\s+/g, '');
			return str.substring(str.length - 4);
		},
		getType(key) {
			return ['储蓄卡', '信用卡'][key];
		}
	}
};
</script>

<style>
.wanl-withdraw .money .symbol {
	font-size: 60rpx;
	margin-right: 10rpx;
}

.wanl-withdraw .money .price {
	display: flex;
	align-items: center;
}
.wanl-withdraw .money .price input {
	/* #ifdef MP */
	height: 100rpx;
	min-height: 100rpx;
	/* #endif */
	width: 100%;
	font-size: 100rpx;
}

.wanl-withdraw .bank {
	display: flex;
	justify-content: space-between;
	align-items: center;
	background-color: #ffffff;
	padding: 20rpx 25rpx;
}
.wanl-withdraw .bank image {
	width: 100rpx;
	height: 100rpx;
}
.wanl-withdraw .bank .content {
}
.wanl-withdraw .bank .action {
	text-align: right;
}
</style>
